package com.i2863.shiroDemo.util;

public class TimeUtil {

    public static String buildWithZero(int i, int len) {
        StringBuilder result = new StringBuilder();
        result.append(i);
        if (result.length() < len) {
            for (int j = 0; j < len - result.length(); j++) {
                result.insert(0, "0");
            }
        }
        return result.toString();
    }

    public static String format(int seconds) {
        int hour = seconds / 3600;
        int minute = (seconds % 3600) / 60;
        int second = seconds % 60;
        StringBuilder result = new StringBuilder();
        if (hour > 0) {
            result.append(buildWithZero(hour, 2)).append(":");
        }
        result.append(buildWithZero(minute, 2)).append(":");
        result.append(buildWithZero(second, 2));
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(format(3599));
    }
}
